//package ca.cbc.mi;
//
//import ch.qos.logback.classic.BasicConfigurator;
//import ch.qos.logback.classic.Level;
//import ch.qos.logback.classic.Logger;
//import ch.qos.logback.classic.LoggerContext;
//import com.theplatform.data.api.DataObjectField;
//import com.theplatform.data.api.Range;
//import com.theplatform.data.api.client.ClientConfiguration;
//import com.theplatform.data.api.marshalling.PayloadForm;
//import com.theplatform.data.api.objects.Feed;
//import com.theplatform.data.api.objects.FieldInfo;
//import com.theplatform.media.api.client.MediaClient;
//import com.theplatform.media.api.client.ReleaseClient;
//import com.theplatform.media.api.data.objects.Media;
//import com.theplatform.media.api.data.objects.Release;
//import com.theplatform.media.api.fields.ReleaseField;
//import com.theplatform.module.authentication.client.AuthenticationClient;
//import org.slf4j.LoggerFactory;
//
//import java.net.UnknownHostException;
///**
// * Created by IntelliJ IDEA.
// * User: arash
// * Date: 22-Dec-2010
// * Time: 3:08:08 PM
// * To change this template use File | Settings | File Templates.
// */
//public class FetchRelease {
//
//    /**
//     * Media Data API sample code that streams the entire result set of Media objects
//     * for a given account
//     */
//
//        /**
//         * @param args args[0] = MPS username, args[1] = MPS password, args[2] = MPS account name.
//         * To get all media across all accounts visible to the username, pass in a null for the
//         * account name.
//         */
//        public static void main(String[] args)
//        {
//            // quiet down logging
////            BasicConfigurator.configureDefaultContext();
////            LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
////            Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
////            rootLogger.setLevel(Level.ERROR);
//
//            // construct an authentication client with credentials
//            args=new String[]{"arash.bizhan-zadeh@cbc.ca","Password1","CBC Dev"};
//            AuthenticationClient authClient = new AuthenticationClient(
//                    "https://identity.auth.theplatform.com/idm",
//                    "mps/" + args[0],
//                    args[1],
//                    (args[2] != null ? new String[] { args[2] } : null));
//
//            // configure the token to expire after 1 minute
//            authClient.setTokenDuration(60000);
//
//            // set up the media client configuration.  this can only be set when the
//            // client is created
//            ClientConfiguration config = new ClientConfiguration();
//
//            // if you want to run calls through a proxy, uncomment the lines below
//            //config.setProxyHost("localhost");
//            //config.setProxyPort(8888);
//
//            // make the client stream results from get() calls,
//            // instead of buffering the objects in memory
//            config.setStreamingResults(true);
//
//            // payload form can be Atom, RSS, or JSON
//            config.setPayloadForm(PayloadForm.JSON);
//
//            // construct the Data Service client using the authentication client
//            ReleaseClient client;
//
//            MediaClient mediaClient;
//            try
//            {
//                client = new ReleaseClient("http://mps.theplatform.com", authClient, config);
//                mediaClient = new MediaClient("http://mps.theplatform.com", authClient, config);
//            }
//            catch (UnknownHostException e)
//            {
//                System.out.println("Unknown host exception: " + e.getMessage());
//                return;
//            }
//
//            // request all visible Media objects
//            Feed<Release> mediaList = client.getAll(
//                    new String[] {
//                        DataObjectField.id.toString(),
//                            ReleaseField.delivery.toString(),
//                            ReleaseField.mediaId.toString(),
//                        DataObjectField.customValues.toString()}, // return title, id, and custom fields
//                    null,   // query (default returns all visible objects)
//                    null,   // sort (default sorts by updated descending)
//                    new Range(1, Range.UNBOUNDED),   // return all objects
//                    true);  // count total results
//
//            System.out.println("Total results: " + mediaList.getTotalResults());
//
//            // stream the results; print id, title, and custom values
//            while (mediaList.getStreamingIterator().hasNext())
//            {
//                Release media = mediaList.getStreamingIterator().next();
//                System.out.println(media.getId() + " : " + media.getDelivery() + "->" + media.getMediaId());
//                Media mediaObject= mediaClient.get(media.getMediaId(),
//                        new String[]{
//                           DataObjectField.title.toString()
//
//                        }, null, null);
//                System.out.printf("Title is %s \n", mediaObject.getTitle());
////                for (FieldInfo field : media.getCustomValues().keySet())
////                {
////                    System.out.println("  field is " + field + " -> " + media.getCustomValues().get(field));
////                }
//            }
//        }
//    }
//
